package com.sdry.basic.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sdry.basic.entity.Pylons;
import com.sdry.basic.service.PylonsService;
import com.sdry.common.BaseController;
import com.sdry.common.TableDataInfo;
import com.sdry.system.entity.SysDept;
import net.sf.json.JSONObject;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 挂架表表控制层
 * @author chenBin
 * @since 2020-03-10 16:14:03
 */
@Controller
@RequestMapping("pylons")
public class PylonsController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private PylonsService pylonsService;

    /**
     * 展示
     * @return
     */
    @RequestMapping("showPylons")
    public String showPylons() {
        return "/td/basis/pylons";
        //return "/td/basis/pylons-vue";
    }

    /**
     * 分页查询
     * @return
     */
    @RequestMapping(value = "queryPylonsPage")
    @ResponseBody
    public TableDataInfo queryPylonsPage(Pylons pylons) {
        logger.info("获取挂架表 sysDept = " + JSONObject.fromObject(pylons));
        Page<Pylons> page = new Page<>(pylons.getPage(),pylons.getLimit());
        QueryWrapper<Pylons> queryWrapper = new QueryWrapper<>();
        if (StringUtils.isEmpty(pylons.getPyNumber())) {
            queryWrapper.eq("del_flag",0L);
        }else {
            queryWrapper.eq("del_flag",0L).like("py_number", pylons.getPyNumber());
        }
        IPage<Pylons> sysDeptIPage = pylonsService.page(page,queryWrapper);
        return getDataTable(sysDeptIPage.getRecords(), sysDeptIPage.getTotal());
    }

    /**
     * 新增
     * @param pylons
     * @return
     */
    @RequestMapping(value = "addPylons")
    @ResponseBody
    public boolean addDept(Pylons pylons) {
        return pylonsService.saveOrUpdate(pylons);
    }

    /**
     * 去编辑页面
     * @param id
     * @return
     */
    @RequestMapping(value = "updatePylons" )
    @ResponseBody
    public String updateDept(Long id) {
        Pylons pylons = null;
        if (id != null){
            pylons = pylonsService.getById(id);
        }
        return JSONObject.fromObject(pylons).toString();
    }

    /**
     * 删除
     * @param pyId 主键ID
     * @return
     */
    @RequestMapping(value = "deletePylons")
    @ResponseBody
    public boolean deletePylons(Long pyId) {
        return pylonsService.deletePylons(pyId);
    }
}